import { log } from '../aop/log';
import { IDefaultMediaOptions } from '../interface';

class MediaStreamConfigure {
	// 设备ID
	public static audioDeviceID: string | undefined = undefined;
	public static videoDeviceID: string | undefined = undefined;
	public static speakerDeviceID: string | undefined = undefined;

	// 默认媒体流参数
	public static defaultMediaOptions: IDefaultMediaOptions = {
		cameraStreamAudioConstraints: { deviceId: this.audioDeviceID, source: 'mic' },
		cameraStreamVideoConstraints: { deviceId: this.videoDeviceID, frameRate: 15, resolution: { width: 640, height: 480 }, source: 'camera' },
		cameraPublishOptions: {
			audio: [{ codec: { name: 'opus' } }],
			video: [
				{ codec: { name: 'vp8' }, maxBitrate: 1024 },
				{ codec: { name: 'h264' }, maxBitrate: 1024 }
			]
		},
		screenStreamAudioConstraints: { source: 'screen-cast' },
		screenStreamVideoConstraints: { frameRate: 15, resolution: { width: 1280, height: 720 }, source: 'screen-cast' },
		screenPublishOptions: {
			audio: [{ codec: { name: 'opus' }, maxBitrate: 64 }],
			video: [
				{ codec: { name: 'vp8' }, maxBitrate: 1024 },
				{ codec: { name: 'h264' }, maxBitrate: 1024 }
			]
		}
	};

	// 默认发布流的参数
	public static defaultPublishOptions = {
		audio: [
			{
				codec: {
					name: 'opus'
				}
			}
		],
		video: [
			{
				codec: {
					name: 'h264'
				},
				maxBitrate: 1024,
				minBitrate: 600 // 640推荐值600，720推荐值1000
			},
			{
				codec: {
					name: 'vp8'
				},
				maxBitrate: 1024,
				minBitrate: 600 // 640推荐值 600，720推荐值1000
			}
		]
	};

	@log('日志消息')
	public static setAudioDeviceID(audioDeviceID: string | undefined) {
		this.audioDeviceID = audioDeviceID;
		return this.audioDeviceID;
	}

	@log('日志消息')
	public static setVideoDeviceID(videoDeviceID: string | undefined) {
		this.videoDeviceID = videoDeviceID;
		return this.videoDeviceID;
	}

	@log('日志消息')
	public static setSpeakerDeviceID(speakerDeviceID: string | undefined) {
		this.speakerDeviceID = speakerDeviceID;
		return this.speakerDeviceID;
	}

	@log('日志消息')
	public static setMediaOptions(mediaOptions: IDefaultMediaOptions) {
		this.defaultMediaOptions = { ...this.defaultMediaOptions, ...mediaOptions };
	}
}

export default MediaStreamConfigure;
